//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.example.controller;

import com.example.common.Result;
import com.example.entity.Employee;
import com.example.service.EmployeeService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import java.util.List;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/employee"})
public class EmployeeController {
    @Resource
    private EmployeeService employeeService;

    public EmployeeController() {
    }

    @GetMapping({"/selectAll"})
    public Result selectAll(Employee employee) {
        List<Employee> list = this.employeeService.selectAll(employee);
        return Result.success(list);
    }

    @GetMapping({"/selectById/{id}"})
    public Result selectById(@PathVariable Integer id) {
        Employee employee = this.employeeService.selectById(id);
        return Result.success(employee);
    }

    @GetMapping({"/selectByOne"})
    public Result selectByOne(@RequestParam Integer id, @RequestParam(required = false) String no) {
        Employee employee = this.employeeService.selectById(id);
        return Result.success(employee);
    }

    @GetMapping({"/selectList"})
    public Result selectList(Employee employee) {
        List<Employee> list = this.employeeService.selectList(employee);
        return Result.success(list);
    }

    @GetMapping({"/selectPage"})
    public Result selectPage(Employee employee, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Employee> pageInfo = this.employeeService.selectPage(employee, pageNum, pageSize);
        return Result.success(pageInfo);
    }

    @PostMapping({"/add"})
    public Result add(@RequestBody Employee employee) {
        this.employeeService.add(employee);
        return Result.success();
    }

    @PutMapping({"/updateById"})
    public Result updateById(@RequestBody Employee employee) {
        this.employeeService.updateById(employee);
        return Result.success();
    }

    @DeleteMapping({"/deleteById/{id}"})
    public Result deleteById(@PathVariable Integer id) {
        this.employeeService.deleteById(id);
        return Result.success();
    }

    @DeleteMapping({"/deleteBatch"})
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        this.employeeService.deleteBatch(ids);
        return Result.success();
    }
}
